#include "BasicElement.h"

namespace gameCG {
	BasicElement::BasicElement() {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glLoadIdentity();
			glGetDoublev(GL_MODELVIEW_MATRIX, m_matrix);
		glPopMatrix();
	
		existTransformation = false;
	}

	void BasicElement::applyTransformations() {
		if (!existTransformation)
			return;
	
		glMatrixMode(GL_MODELVIEW);
		glMultMatrixd(m_matrix);
	}

	void BasicElement::clearTransformations() {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glLoadMatrixd(m_matrix);
			glLoadIdentity();
			glGetDoublev(GL_MODELVIEW_MATRIX, m_matrix);
		glPopMatrix();
	
		existTransformation = false;
	}

	void BasicElement::Rotate(GLfloat angle, GLfloat aX, GLfloat aY, GLfloat aZ) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glLoadMatrixd(m_matrix);
			glRotatef(angle, aX, aY, aZ);
			glGetDoublev(GL_MODELVIEW_MATRIX, m_matrix);
		glPopMatrix();
	
		existTransformation = true;
	}

	void BasicElement::Translate(GLfloat dX, GLfloat dY, GLfloat dZ) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glLoadMatrixd(m_matrix);
			glTranslatef(dX, dY, dZ);
			glGetDoublev(GL_MODELVIEW_MATRIX, m_matrix);
		glPopMatrix();
	
		existTransformation = true;
	}

	void BasicElement::Scale(GLfloat cX, GLfloat cY, GLfloat cZ) {
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
			glScalef(cX, cY, cZ);
			glGetDoublev(GL_MODELVIEW_MATRIX, m_matrix);
		glPopMatrix();
	
		existTransformation = true;
	}
	
}
